import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;


class Login extends JDialog implements ActionListener
{

    JTextField user;
    JPasswordField pass;

    String username = "db2admin"; // Need you database Username and password
    String password = "crossbow";
    String database = "RENTMOV";

    int mship;

    Login(){
		new UserInterface(92);
		/*
        super();

        Container c = getContentPane();

        JPanel panel = new JPanel(new FlowLayout());
        user = new JTextField();
        user.setPreferredSize(new Dimension(90,20));
        panel.add(user);

        pass = new JPasswordField();
        pass.setPreferredSize(new Dimension(90,20));
        panel.add(pass);

        JButton login = new JButton("Login");
        login.setPreferredSize(new Dimension(80,20));
        login.addActionListener(this);
        login.setActionCommand("login");
        panel.add(login);

        c.add(panel);

        Toolkit tk;
        Dimension d;
        tk = Toolkit.getDefaultToolkit();
        d = tk.getScreenSize();
        setSize(300,70);
        setLocation((d.width/2)-150, (d.height/2)-35);
        setVisible(true);

        getRootPane().setDefaultButton(login);
        //*/
    }

    public void actionPerformed(ActionEvent e){

        if(e.getActionCommand().equals("login")){

            String SQLStatement = "select M.mship# from members M where " +
                "username=\'" + user.getText().trim() + "\' and password=\'" +
                 new String(pass.getPassword()) + "\'";

            DBQTable dbq = new DBQTable(database); // Need you database name

            try{
                JTable table = dbq.getTable(username,password,
                                SQLStatement);

                mship = (Integer) table.getModel().getValueAt(0,0);
                System.out.println("User's Membership Number =  " + mship);
                setVisible(false);
                new UserInterface(mship);

            }catch (ArrayIndexOutOfBoundsException x){

                JOptionPane.showMessageDialog(this,
                    "Invaled Username or Password",
                    "Failed Login",
                    JOptionPane.ERROR_MESSAGE);

            }catch (Exception x){
                x.printStackTrace();
            }


        }


    }

}